<!DOCTYPE html>
<html>
<head>
    <title>我的</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="stylesheet" href="${s.base}/mobile/css/weui.min.css">
    <link rel="stylesheet" href="${s.base}/mobile/css/jquery-weui.css">
    <link rel="stylesheet" href="${s.base}/mobile/css/base.css">
    <link rel="stylesheet" href="${s.base}/mobile/css/component.css">
    <style>
        .cyt-top {
            width: 100%;
            height: auto;
            background: #fff;
            position: fixed;
            top: 0px;
            left: 0px;
        }
        .cyt-top-item {
            width: 20%;
            height: 2.2rem;
            line-height: 2.2rem;
            text-align: center;
            float: left;
            font-size: 14px;
            border-bottom: 0.01rem solid #D9D9D9;
        }
        .cyt-top-item-select {
            color: #ff3b30;
        }
        .xyg-detail-no {
            width: 100%;
            height: 6rem;
            margin: 6rem auto;
        }
        .xyg-detail-no img, .xyg-detail-no .xyg-detail-no-img {
            width: 3rem;
            height: 3rem;
        }
        .xyg-detail-no .xyg-detail-no-img {
            margin: auto;
        }
        .xyg-detail-no .xyg-detail-no-text {
            width: 100%;
            text-align: center;
            height: 1.8rem;
            line-height: 1.8rem;
            font-size: 0.3rem;
            color: #515151;
        }
        .weui-photo-browser-modal{z-index: 99;}
    </style>
</head>
<body style="background: #f0eff4;">
<div class="cyt-top">
    <div onclick="doData('',this)" id="zeroStatus" class="cyt-top-item <#if status == ''>cyt-top-item-select</#if>">全部</div>
    <div onclick="doData('1',this)" id="oneStatus" class="cyt-top-item <#if status == '1'>cyt-top-item-select</#if>">销售</div>
    <div onclick="doData('2',this)" id="twoStatus" class="cyt-top-item <#if status == '2'>cyt-top-item-select</#if>">下架</div>
    <div onclick="doData('3',this)" id="threeStatus" class="cyt-top-item <#if status == '3'>cyt-top-item-select</#if>">结算</div>
    <div onclick="doData('4',this)" id="fourStatus" class="cyt-top-item <#if status == '4'>cyt-top-item-select</#if>">纠纷</div>
    <div class="clearBoth"></div>
</div>
<div style="height:2.2rem;width:100%;"></div>
<!--搜索开始-->
<div class="xyg-comp-search">
    <div class="weui-search-bar" id="searchBar">
        <form class="weui-search-bar__form">
            <div class="weui-search-bar__box">
                <i class="weui-icon-search"></i>
                <input type="search" class="weui-search-bar__input" onchange="search()" id="searchInput" placeholder="搜索" required>
                <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
            </div>
            <label class="weui-search-bar__label" id="searchText">
                <span>搜索</span>
                <i class="weui-icon-search"></i>
            </label>
        </form>
        <a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>
    </div>
</div>
<!--搜索结束-->
<div class="xyg-comp-list-select">
    <!--<div style="width:100%; height:1.2rem; line-height: 1.2rem; text-align: center; color: #8a898e; margin-top: 0.5rem; ">
        2019-11-20 11:20:09
    </div>-->
    <!--内容开始-->
    <div class="xyg-content" id="showContent">

    </div>
    <!--内容结束-->
</div>

<div class="xyg-product-list_loadmore weui-loadmore clearBoth">
    <i class="weui-loading"></i>
    <span class="weui-loadmore__tips">正在加载</span>
</div>

<div class="xyg-detail-no" style="display: none;" id="showNoContent">
    <div class="xyg-detail-no-img"><img src="${s.base}/mobile/images/icon_dd.png"/></div>
    <div class="xyg-detail-no-text">暂时没有相关信息哦</div>
</div>

<!--底部菜单开始-->
<div style="width:100%; height:2.5rem;"></div>
<div class="xyg-comp-bottom">
    <div class="xyg-comp-bottom-item">
        <a href="javascript:void(0)" onclick="goFistPage('${memberId}')">
            <img src="${s.base}/mobile/images/menu_icon_1.png"/>
            <div class="xyg-comp-bottom-item-text ">首页</div>
        </a>
    </div>
    <div class="xyg-comp-bottom-item">
        <a href="javascript:void(0)" onclick="goBankPage('${memberId}')">
            <img src="${s.base}/mobile/images/menu_icon_2.png"/>
            <div class="xyg-comp-bottom-item-text ">银行兑换</div>
        </a>
    </div>
    <div class="xyg-comp-bottom-item">
        <a href="javascript:void(0)" onclick="goDetailPage('${memberId}')">
            <img src="${s.base}/mobile/images/menu_icon_3_a.png"/>
            <div class="xyg-comp-bottom-item-text select-text">权益管理</div>
        </a>
    </div>
    <div class="xyg-comp-bottom-item">
        <a href="javascript:void(0)" onclick="goMyPage('${memberId}')">
            <img src="${s.base}/mobile/images/menu_icon_4.png"/>
            <div class="xyg-comp-bottom-item-text">账户中心</div>
        </a>
    </div>
    <div class="clearBoth"></div>
</div>
<!--底部菜单结束-->
<script src="${s.base}/mobile/js/jquery-2.1.4.js"></script>
<script src="${s.base}/mobile/js/jquery-weui.js"></script>
<script src="${s.base}/mobile/js/swiper.js"></script>
<script src="${s.base}/mobile/fonts/iconfont.js"></script>
<script src="${s.base}/mobile/js/component.js"></script>

<script src="${s.base}/mobile/js/base.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
<!--js分享代码开始-->
<input type="hidden" value="${jSTicketShareResponse.appid}" id="appid" />
<input type="hidden" value="${jSTicketShareResponse.fxTitle}" id="fxTitle" />
<input type="hidden" value="${jSTicketShareResponse.fxImgUrl}" id="fxImgUrl" />
<input type="hidden" value="${jSTicketShareResponse.fxDesc}" id="fxDesc" />
<input type="hidden" value="${jSTicketShareResponse.fxUrl}" id="fxUrl" />
<input type="hidden" value="${jSTicketShareResponse.nonceStr}" id="nonceStr" />
<input type="hidden" value="${jSTicketShareResponse.timestamp}" id="timestamp" />
<input type="hidden" value="${jSTicketShareResponse.signature}" id="signature" />
<script src="${s.base}/mobile/js/share.js?322rre4433421"></script>
<!--js分享代码结束-->
<script>
    var memberId = '${memberId}';
    var status = "";
    var itemName = "";
    var pageStart = 0;
    var num = 3;
    var loading = false;  //状态标记
    sendPost();
    $(document).ready(function (e) {
        initPage();
        $(document.body).infinite().on("infinite", function () {
            if (loading) return;
            loading = true;
            sendPost();
        });
    });

    /*$("#searchInput").bind("propertychange input",function(){
    })*/

    function search(){
        var name = $("#searchInput").val();
        itemName = name;
        pageStart = 0;
        initPage();
        sendPost();
    }

    function sendPost() {
        $("#showNoContent").hide();
        pageStart++;
        $.post("/phone/shopOrderCouponJsonList", {
            pageSize: num,
            pageNum: pageStart,
            status: status,
            memberId: memberId,
            itemName:itemName
        }, function (resultInfo) {
            //1、未使用，2、已使用，3、已过期
            if (resultInfo.data != null && resultInfo.data.length > 0) {
                for (var j = 0; j < resultInfo.data.length; j++) {
                    var orderCoupon = resultInfo.data[j];
                    // 状态
                    var status = orderCoupon.status;
                    var statusStr = "";
                    var stockStr = "权益已入库";
                    if (status == "1"){
                        statusStr = '<div style="float: right; color: #fc8521; " onclick="updateStatus(2,\''+orderCoupon.id+'\')">下架</div>'
                        stockStr = "权益未入库";
                    }else if (status == "2"){
                        statusStr =  '<div style="float: right; color: #fc8521; " onclick="updateStatus(1,\''+orderCoupon.id+'\')">上架</div>'
                        stockStr = "权益未入库";
                    }else if (status == "5"){
                        statusStr =  '<div style="float: right; color: #fc8521; " onclick="stockIn()">已入库</div>'
                    }else if (status == "3"){
                        statusStr =  '<div style="float: right; color: #fc8521; ">结算</div>'
                    }else if (status == "4"){
                        var issueStatus = orderCoupon.issueStatus;
                        if (issueStatus == "1"){
                            statusStr = '<div style="float: right; color: #fc8521; " >纠纷</div>'
                        }else if (issueStatus == "2"){
                            statusStr =  '<div style="float: right; color: #fc8521; " onclick="updateIssueStatus(\''+orderCoupon.id+'\')">纠纷中</div>'
                        }else if (issueStatus == "3"){
                            statusStr =  '<div style="float: right; color: #fc8521; " onclick="updateIssueStatus(\''+orderCoupon.id+'\')">申诉中</div>'
                        }else if (issueStatus == "4"){
                            statusStr =  '<div style="float: right; color: #fc8521; " onclick="updateIssueStatus(\''+orderCoupon.id+'\')">纠纷无效</div>'
                        }else if (issueStatus == "5"){
                            statusStr =  '<div style="float: right; color: #fc8521; " onclick="updateIssueStatus(\''+orderCoupon.id+'\')">纠纷有效</div>'
                        }
                    }
                    var createTimeStr = new Date(orderCoupon.createTime).format("yyyy-MM-dd hh:mm:ss");
                    var itemListHtml = '<div style="width:100%; height:1.2rem; line-height: 1.2rem; text-align: center; color: #8a898e; margin-top: 0.5rem; ">\
                            '+createTimeStr+'\
                        </div>\
                        <div style="width:90%; margin: 0.2rem 3%; line-height: 2rem; border-radius: 0.5rem; background: #fff; padding-left:2%;padding-right:2%;  ">\
                            <div style="width:100%; height:2rem; line-height: 2rem; border-bottom: 0.01rem solid #f0eff4;">'+stockStr+'';
                    // 判断销售和下架
                    itemListHtml+=statusStr;
                    itemListHtml+='<div class="clearBoth"></div>\
                            </div>\
                            <div style="width:100%;line-height: 2rem; ">\
                            <div style="width:30%; float: left; height: 6rem;">\
                            <img src="'+orderCoupon.image+'" style="height: 90%; margin: 5% 0px; width: auto; max-width:96%"/>\
                            </div>\
                            <div style="width:70%; float: left;">\
                            <div style="width:92%; margin: 0rem 4%; line-height: 1.2rem; float: left;">\
                            '+orderCoupon.catName+'\
                            </div>\
                            <div style="width:92%;margin: 0rem 4%; line-height: 1.2rem; float: left;">\
                            商品名称：'+orderCoupon.itemName+'\
                        </div>\
                        <div style="width:92%; margin: 0rem 4%; line-height: 1.2rem; float: left;">\
                            卷码：'+orderCoupon.qrImage+'\
                        </div>\
                        <div style="width:92%;margin: 0rem 4%; line-height: 1.2rem; float: left;">\
                            金额：<span style="color: #ff0000;">￥'+orderCoupon.price+'</span>\
                        </div>\
                        <div style="width:92%;margin: 0rem 4%; line-height: 1.2rem; float: left;">\
                            提醒：按上传先后时间出货，勿催！\
                    </div>\
                        </div>\
                        <div class="clearBoth"></div>\
                            </div>\
                            <div onclick="showImg(\''+orderCoupon.image+'\')" style="width:100%; height:2rem; line-height: 2rem; border-top: 0.01rem solid #f0eff4;">\
                            查看权益截屏\
                            <div style="float: right;">\
                            <svg class="icon" aria-hidden="true">\
                            <use xlink:href="#icon-xiangyou"></use>\
                            </svg>\
                            </div>\
                            <div class="clearBoth"></div>\
                            </div>\
                            </div>';

                    $("#showContent").append(itemListHtml);
                    loading = false;
                    if (!resultInfo.hasNextPage) {
                        $(document.body).destroyInfinite();
                        $(".xyg-product-list_loadmore").hide();
                    }
                }
            } else {
                $(document.body).destroyInfinite();
                $(".xyg-product-list_loadmore").hide();
                $("#showNoContent").show();
            }
        });
    }

    function hideImage(obj) {
        console.log(1);
        // $(".weui-gallery").attr("style","display: none");
        $(obj).hide();
    }

    function showImg(url) {
        var pb1 = $.photoBrowser({
            items: [
                url
            ]
        });
        pb1.open();
    }

    function initPage() {
        $(document.body).infinite();
        $(".xyg-product-list_loadmore").show();
    }

    function doData(s, obj) {
        $("#showContent").html("");
        $(".cyt-top-item").removeClass("cyt-top-item-select");
        $(obj).addClass("cyt-top-item-select");
        pageStart = 0;
        status = s;
        initPage();
        sendPost();
    }

    function stockIn(){
        $.toast("已入库，不能下架", "text");
        return false;
    }

    function updateStatus(status, id) {
        $.showLoading("正在提交中");
        $.ajax({
            type: "POST",
            url: "/phone/updateOrderCouponStatusById?id="+id+"&status="+status,
            success: function(result){
                if(0==result.code){
                    $.hideLoading();
                    var str="";
                    if(status == "1"){
                        str="上架成功"
                    }
                    if(status == "2"){
                        str="下架成功"
                    }
                    $.toast(str, "text");
                    // 刷新当前页面
                    window.location.href="/phone/detail?memberId="+memberId+"&status="+status;
                }else{
                    $.hideLoading();
                    $.toast(result.returnInfo.errorMsg, "text");
                }
            },
            error: function(result){
                $.hideLoading();
                $.toast(result, "text");
            }
        });
    }

    function updateIssueStatus(id){
        window.location.href="/phone/complain?memberId="+memberId+"&id="+id;
    }
</script>
</body>
</html>

